package models

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Relation struct {
	BeFollow int64 `gorm:"primaryKey;autoIncrement:false"`
	Follow   int64 `gorm:"primaryKey;autoIncrement:false"`
	IsDel    bool  `gorm:"column:is_del"` //默认未删除
}

/**
1)查找用户1的粉丝列表:
	select follow from relation where be_follow =1 and is_del =false
2)查找用户1的关注列表:
	select be_follow from relation where follow =1 and is_del =false

3)用户1关注用户2:
	1. 用户1是否关注了用户2
	select isDel from relation where follow =1 and be_follow =2
	2. 下一步操作
		2.1 isDel:true  更新isDel=false
		2.2 isDel:false 不做操作
	3. 查不到
	insert into relation(be_follow, follow, is_del) values(2,1,false)

4)用户1取关用户2:
	1. 用户1是否关注了用户2
	select isDel from relation where follow =1 and be_follow =2
	2. 下一步操作
		2.1 isDel:true  不做操作
		2.2 isDel:false 更新isDel=true
	3. 查不到 不做操作

5)用户1是否关注了用户2:
	select isDel from relation where follow =1 and be_follow =2
*/

type RelationRequest struct {
	ToUserId   int64 `form:"to_user_id" json:"to_user_id" binding:"required"`
	ActionType int32 `form:"action_type" json:"action_type" binding:"required"`
}

type RelationResponse struct {
	Response
	UserList []User `json:"user_list"`
}

// ResponseRelationSuccess 返回关系列表成功
func ResponseRelationSuccess(c *gin.Context, userList []User) {
	c.JSON(http.StatusOK, &RelationResponse{
		Response: Response{StatusCode: CodeSuccess, StatusMsg: ResCode.Msg(CodeSuccess)},
		UserList: userList,
	})
}

// ResponseRelationError 返回关系列表错误
func ResponseRelationError(c *gin.Context, code ResCode) {
	c.JSON(http.StatusOK, &RelationResponse{
		Response: Response{StatusCode: code, StatusMsg: code.Msg()},
		UserList: []User{},
	})
}
